package com.ywk.base.javaBase.enumDemo;

import java.util.HashMap;

/**
 * @Author zbh
 * @Date 2023/11/3
 */
public class EnumMethodTest {
    public static void main(String[] args) {
        Season autumn = Season.AUTUMN;
        // 获取当前枚举对象的名称
        System.out.println(autumn.name());

        // 输出该枚举对象的次序，从0开始
        System.out.println(autumn.ordinal());

        // 返回所有的枚举对象
        Season[] seasons = Season.values();
        for (Season season : seasons) {
            System.out.println(season);
        }

        // 将字符串转化为枚举对象,要求字符串必须为已有的常量名，否则会爆出一个异常
        Season autumn1 = Season.valueOf("AUTUMN");
        System.out.println(autumn1);

        // 比较两个枚举常量，比较的就是编号
        // AUTUMN的编号减去SUMMER的编号
        System.out.println(Season.AUTUMN.compareTo(Season.SUMMER));

        System.out.println(BusinessStatus.SUCCESS.ordinal());
        System.out.println(BusinessStatus.FAIL);

        HashMap<String, String> map = new HashMap<>();
        map.put("1","1");
        System.out.println(map.get(""));

        System.out.println(BusinessStatus.SUCCESS.name().equals("SUCCESS"));

        Season season = Season.valueOf("SUMMER");
        switch (season){
            case AUTUMN:
                System.out.println(Season.AUTUMN.getDesc());
            case SUMMER:
                System.out.println(Season.SUMMER.getDesc());
            default:
                System.out.println(season.getDesc());
        }
    }

}
